<?php
declare (strict_types = 1);
namespace app\index\middleware;
use think\facade\Cache;
class bdTokenCheck
{
    public function handle($request, \Closure $next)
    {
        $sessionid=$request->param('sessionid');
        if($sessionid == ''){
            return json(['code'=>200,'data'=>['code' =>201, 'msg' => 'sessionid不能为空','cs'=>$sessionid]]);
        }
        
        $rebdtk=$request->header('bdtk');

        $sebdtk=Cache::pull('tpbdtk:'.$sessionid);

        if(($rebdtk != $sebdtk) || ($rebdtk=='') || ($sebdtk==null) ) {
            return json(['code'=>200,'data'=>['code' =>201, 'msg' => 'bdtk验证失败','h'=>$rebdtk,'s'=>$sebdtk,'sid'=>$sessionid]]);
        }
        return $next($request);
    }
}